package com.wanxi.udp.demo3组播发送数据给多个接收端;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * 组播消息发送端
 */
public class UDPMulticastSend {
    public static void main(String[] args) throws IOException {
        System.out.println("组播发送端启动");
        //1. 创建接收端socket
        DatagramSocket ds = new DatagramSocket();

        String s = "hello 组播消息";
        byte[] bytes = s.getBytes();
        //2.  得到加入组播地址
        InetAddress address = InetAddress.getByName("224.0.3.3");
        int port = 10000;
        //3. 创建消息数据包
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

        //4. 进行组播消息发送
        ds.send(dp);

        ds.close();
    }
}
